package leetcode.每日一题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ：zsy
 * @date ：Created 2021/6/19 15:40
 * @description：https://leetcode-cn.com/problems/power-set-lcci/
 */
public class 幂集 {

    @Test
    public void Test() {
        Solution solution = new Solution();
        List<List<Integer>> subsets = solution.subsets(new int[]{1, 2, 3});
        for (List<Integer> subset : subsets) {
            System.out.println(subset.toString());
        }
    }

    class Solution {
        List<List<Integer>> ans = new ArrayList<>();
        int[] nums;
        public List<List<Integer>> subsets(int[] nums) {
            this.nums = nums;
            dfs(0, new ArrayList<>());
            return ans;
        }

        private void dfs(int index, ArrayList<Integer> curList) {
            if (index == nums.length) {
                ans.add(new ArrayList<>(curList));
                return;
            }

            //不拿
            dfs(index + 1, curList);
            //拿
            curList.add(nums[index]);
            dfs(index + 1, curList);
            curList.remove(curList.size() - 1);
        }
    }
}













